﻿namespace TanzimSaqib.NoBrainer.Sample.Account
{
    using System.Web.Security;
    using DataAccess;
    using System;
    using Controllers;

    public partial class Login : ViewBase<AccountController, AccountModel>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(IsPostBack)
            {
                InvokeController(v => Controller.Login(Model));       

                if(Model.IsValid)
                {
                    FormsAuthentication.RedirectFromLoginPage(Model.UserName, Model.PersistentCookieEnabled);
                }
            }
            else
            {
                if(Request.IsAuthenticated)
                {
                    Response.Redirect("~/Account/Manage.aspx");
                }
            }
        }
    }
}
